package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.finance.vo.GoodsDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.InvoiceGoods;
import com.ruoyi.finance.service.IInvoiceGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 开票商品Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/finance/goods")
public class InvoiceGoodsController extends BaseController
{
    @Autowired
    private IInvoiceGoodsService invoiceGoodsService;

    /**
     * 查询开票商品列表
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceGoods invoiceGoods)
    {
        startPage();
        List<InvoiceGoods> list = invoiceGoodsService.selectInvoiceGoodsList(invoiceGoods);
        return getDataTable(list);
    }

    /**
     * 导出开票商品列表
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:export')")
    @Log(title = "开票商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceGoods invoiceGoods)
    {
        List<InvoiceGoods> list = invoiceGoodsService.selectInvoiceGoodsList(invoiceGoods);
        ExcelUtil<InvoiceGoods> util = new ExcelUtil<InvoiceGoods>(InvoiceGoods.class);
        util.exportExcel(response, list, "开票商品数据");
    }

    /**
     * 获取开票商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invoiceGoodsService.selectInvoiceGoodsById(id));
    }

    /**
     * 新增开票商品
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:add')")
    @Log(title = "开票商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvoiceGoods invoiceGoods)
    {
        return toAjax(invoiceGoodsService.insertInvoiceGoods(invoiceGoods));
    }

//    @PostMapping("/toadd/{id}")
//    public AjaxResult toadd(@PathVariable("id") Long id @RequestBody InvoiceGoods invoiceGoods){
//
//        return AjaxResult.success(invoiceGoodsService.toadd(goodsDto));
//
//    }

    /**
     * 修改开票商品
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:edit')")
    @Log(title = "开票商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceGoods invoiceGoods)
    {
        return toAjax(invoiceGoodsService.updateInvoiceGoods(invoiceGoods));
    }

    /**
     * 删除开票商品
     */
    @PreAuthorize("@ss.hasPermi('finance:goods:remove')")
    @Log(title = "开票商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invoiceGoodsService.deleteInvoiceGoodsByIds(ids));
    }
}
